﻿using Abp.AspNetCore;
using Abp.AspNetCore.Configuration;
using Abp.Modules;
using Microsoft.Extensions.Configuration;
using Admin.Navigation;
using Microsoft.AspNetCore.Hosting;

namespace Admin
{
    [DependsOn(typeof(AbpAspNetCoreModule),
        typeof(AdminApplicationModule),
        typeof(AdminEntityFrameworkCoreModule))]
    public class AdminAspNetCoreModule : AbpModule
    {
        private readonly IConfigurationRoot _configuration;

        public AdminAspNetCoreModule(IHostingEnvironment env)
        {
            _configuration = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json").Build();
        }

        public override void PreInitialize()
        {
            Configuration.DefaultNameOrConnectionString = _configuration.GetConnectionString("Sqlite");
            Configuration.Modules.AbpAspNetCore()
                .CreateControllersForAppServices(typeof(AdminApplicationModule).Assembly);
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(AdminAspNetCoreModule).Assembly);
        }
    }
}